package com.uzai.console.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.uzai.console.dto.dy.dyorder.*;
import com.uzai.console.dto.groupsendjob.GroupSendJobConditionOrderDto;
import com.uzai.console.dto.vph.vphorder.VphFindUnReceicedDto;
import com.uzai.console.entity.DyOrder;
import com.uzai.console.entity.VphOrder;
import com.uzai.console.vo.dy.dyorder.DyOrderReportVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public interface DyOrderMapper {
    int deleteById(@Param("id") Long id, @Param("merId") Long merId);

    int deleteByParam(@Param("query") DyOrderQuery query);

    int insert(DyOrder record);

    int insertSelective(DyOrder record);

    DyOrder selectById(@Param("id") Long id, @Param("merId") Long merId);

    int updateByIdSelective(DyOrder record);

    int updateById(DyOrder record);

    int updateStatus(DyOrder record);

    /**
     * 分页查询
     * @param page
     * @param query
     * @return
     */
    ArrayList<DyOrder> findByList(Page<DyOrder> page, @Param("query") DyOrderQuery query);

    /**
     * 查询所有
     * @param query
     * @return
     */
    ArrayList<DyOrder> findByList(@Param("query") DyOrderQuery query);

    /**
     * 查询订单统计信息
     * @param query
     * @return
     */
    DyOrderReportVo findDyOrderReport(@Param("query") DyOrderQuery query);

    /**
     * 解绑用户
     * @param
     * @return
     */
    Integer unbindUser(DyOrderUnbindUserDto jdOrderUnbindUserDto);

    /**
     * 绑定用户
     * @param
     * @return
     */
    Integer bindUser(DyOrderBindUserDto jdOrderBindUserDto);

    /**
     * 修改解冻时间
     * @param
     * @return
     */
    Integer updateThawTime(DyOrderThawTimeDto jdOrderThawTimeDto);

    /**
     * 查询所有未绑定用户的订单
     * @param page
     * @return
     */
    ArrayList<DyOrder> findUnbindUserList(Page<DyOrder> page, @Param("query") DyOrderUnbindDtoQuery query);

    /**
     * 查询所有未绑定用户的订单统计
     * @param query
     * @return
     */
    DyOrderReportVo findUnbindUserReport(@Param("query") DyOrderUnbindDtoQuery query);

    /**
     * 删除所有未绑定用户的订单
     * @param dyOrderDeleteUnbindDto
     * @return
     */
    Integer deleteUnbindUserList(DyOrderDeleteUnbindDto dyOrderDeleteUnbindDto);

    /**
     * 查询7天前未收货的订单
     * @param dyFindUnReceicedDto
     * @return
     */
    ArrayList<DyOrder> findUnReceivedList(DyFindUnReceicedDto dyFindUnReceicedDto);

    /**
     * 查询7天前冻结的订单
     * @param dyFindUnReceicedDto
     * @return
     */
    ArrayList<DyOrder> findFreezedList(DyFindUnReceicedDto dyFindUnReceicedDto);
    
    /**
     * 批量替换机器人信息
     * @param merId
     * @return
     */
    int batchUpdateDeviceInfo(@Param("oldDeviceUniqueId") Long oldDeviceUniqueId, @Param("newDeviceUniqueId") Long newDeviceUniqueId, @Param("merId") Long merId);

    /**
     * 将订单状态从付款完成更新到订单结算
     *
     * @param endTime
     * @param userId
     * @param merId
     */
    int updateStatusPayCompleteToSettle(@Param("startTime") Integer startTime, @Param("endTime") Integer endTime, @Param("userId") Long userId, @Param("merId") Long merId,
                                        @Param("status") Integer status, @Param("sourceStatus") List<Integer> sourceStatus);


    /**
     * 将旧会员的订单合并到新会员身上
     *
     * @param userIdOld
     * @param userIdNew
     * @param merId
     */
    int dyOrderMerge(@Param("userIdOld") Long userIdOld, @Param("userIdNew") Long userIdNew, @Param("merId") Long merId);

    List<DyOrder> selectExistsOrderUserIdWithCondition(@Param("condition") GroupSendJobConditionOrderDto conditionOrder);
}